package lianbiaoti;

public class Test {
    static class Node{
        public int val;
        public Node next;

        public Node(int val) {
            this.val = val;
        }
    }
    public Node head;
    public void creatList(){
        Node node = new Node(10);
        Node node1 = new Node(11);
        Node node2 = new Node(12);
        Node node3 = new Node(13);
        Node node4 = new Node(14);
        node.next=node1;
        node1.next=node2;
        node2.next=node3;
        node3.next=node4;
        node4.next=null;
          head=node;


    }
    public void display(){
        Node cur=head;
        while (cur!=null){
            System.out.println(cur.val);
            cur=cur.next;
        }
    }
    public Node addFirst(int val){
        Node node=new Node(val);
        node.next=head;
        head=node;
        return node;
    }
    public Node addFirst2(Node node){
        node.next=head;
        head=node;
        return node;
    }

    public Node fanZhuan(){
        Node cur=head.next;
        head.next=null;
        while (cur!=null) {
            Node curnext=cur.next;

            cur.next=head;
            head=cur;
            cur=curnext;
        }
        return cur;

    }
}
